*************************************************************
** Pandemic Performance: Women Leaders in the Covid-19 Crisis
** Andrea Aldrich & Nicholas Lotito, Yale University
*************************************************************

*ssc install estout

*************************************************************
** STAY HOME ORDER
*************************************************************

use "stayhome.dta", clear
gen total_cases_log = log(total_cases)
gen gdp_per_capita_log = log(gdp_per_capita)
egen id = group(country)
gen pop_density_log = log(population_density)

label variable percent_woman "Women Legislature"
label variable head_of_gov_female "Woman Leader"
label variable total_cases_log "Total Cases"
label variable global_lag "Global Adoption"
label variable polity "Polity Score"
label variable gdp_per_capita_log "GDP Per Capita"
label variable pop_density_log "Population Density"
label variable system "Parliamentary System" // or parliament-elected president
label variable left "Left Government"

// Cox regression
stset stop, id(country) f(status)
stcox head_of_gov_female percent_woman total_cases_log global_lag ///
	polity gdp_per_capita_log pop_density_log system left, efron
eststo stayhome

// No covariates
stcox head_of_gov_female, efron
eststo stayhome_leader
stcox percent_woman, efron
eststo stayhome_parliament

// Logit with random effects
xtset id stop
xtlogit status head_of_gov_female percent_woman total_cases_log global_lag ///
	polity gdp_per_capita_log pop_density_log system left, re
eststo stayhome_re
	
*************************************************************
** SCHOOL CLOSING
*************************************************************

use "school.dta", clear
gen total_cases_log = log(total_cases)
gen gdp_per_capita_log = log(gdp_per_capita)
egen id = group(country)
gen pop_density_log = log(population_density)
label variable percent_woman "Women Legislature"
label variable head_of_gov_female "Woman Leader"
label variable total_cases_log "Total Cases"
label variable global_lag "Global Adoption"
label variable polity "Polity Score"
label variable gdp_per_capita_log "GDP Per Capita"
label variable pop_density_log "Population Density"
label variable system "Parliamentary System" // or parliament-elected president
label variable left "Left Government"

// Cox regression
stset stop, id(country) f(status)
stcox head_of_gov_female percent_woman total_cases_log global_lag ///
	polity gdp_per_capita_log pop_density_log system left, efron
eststo school
	
// No covariates
stcox head_of_gov_female, efron
eststo school_leader
stcox percent_woman, efron
eststo school_parliament

// Logistic regression with random effects
xtset id stop
xtlogit status head_of_gov_female percent_woman total_cases_log global_lag ///
	polity gdp_per_capita_log pop_density_log system left, re
eststo school_re
	
*************************************************************
** INFORMATION CAMPAIGN
*************************************************************

use "info.dta", clear
gen total_cases_log = log(total_cases)
gen gdp_per_capita_log = log(gdp_per_capita)
egen id = group(country)
gen pop_density_log = log(population_density)
label variable percent_woman "Women Legislature"
label variable head_of_gov_female "Woman Leader"
label variable total_cases_log "Total Cases"
label variable global_lag "Global Adoption"
label variable polity "Polity Score"
label variable gdp_per_capita_log "GDP Per Capita"
label variable pop_density_log "Population Density"
label variable system "Parliamentary System" // or parliament-elected president
label variable left "Left Government"

// Cox regression
stset stop, id(id) f(status)
stcox head_of_gov_female percent_woman total_cases_log global_lag ///
	polity gdp_per_capita_log pop_density_log system left, efron
eststo info

// No covariates
stcox head_of_gov_female, efron
eststo info_leader
stcox percent_woman, efron
eststo info_parliament

// Logistic regression with random effects
xtset id stop
xtlogit status head_of_gov_female percent_woman total_cases_log global_lag ///
	polity gdp_per_capita_log pop_density_log system left, re
eststo info_re

// Create LaTeX tables
esttab stayhome school info using "main.tex", alignment(D{.}{.}{-1}) ///
	eform mtitles("Stay Home" "School Closing" "Info. Campaign") label booktabs replace ///
	title(Main Results\label{tab:main}) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) scalar("N_sub Countries")

esttab stayhome_re school_re info_re using "main-re.tex", alignment(D{.}{.}{-1}) ///
	mtitles("Stay Home" "School Closing" "Info. Campaign") label booktabs replace scalar("N_sub Countries") ///
	title(Discrete-Time Model\label{tab:main-re}) star(+ 0.10 * 0.05 ** 0.01 *** 0.001)

esttab stayhome_leader stayhome_parliament school_leader school_parliament info_leader info_parliament using "nocovar.tex", alignment(D{.}{.}{-1}) ///
	eform mgroups("Stay Home" "School Closing" "Info. Campaign", pattern(1 0 1 0 1 0)) label booktabs replace scalar("N_sub Countries") ///
	title(Main Outcomes without Covariates\label{tab:nocovar}) nomtitles nonumbers star(+ 0.10 * 0.05 ** 0.01 *** 0.001)
// Manually convert output float to sidewaystable

***************************************************
** ROBUSTNESS CHECKS
***************************************************

// MODEL 1A: STAY HOME (minimal exceptions)
use "stayhome2.dta", clear
gen total_cases_log = log(total_cases)
gen gdp_per_capita_log = log(gdp_per_capita)
egen id = group(country)
gen pop_density_log = log(population_density)

label variable percent_woman "Women Legislature"
label variable head_of_gov_female "Woman Leader"
label variable total_cases_log "Total Cases"
label variable global_lag "Global Adoption"
label variable polity "Polity Score"
label variable gdp_per_capita_log "GDP Per Capita"
label variable pop_density_log "Population Density"
label variable system "Parliamentary System" // or parliament-elected president
label variable left "Left Government"

stset stop, id(country) f(status)
stcox head_of_gov_female percent_woman total_cases_log global_lag ///
	polity gdp_per_capita_log pop_density_log system left, efron
eststo stayhome2

// MODEL 2A: SCHOOL CLOSING (all levels)
use "school2.dta", clear
gen total_cases_log = log(total_cases)
gen gdp_per_capita_log = log(gdp_per_capita)
egen id = group(country)
gen pop_density_log = log(population_density)

label variable percent_woman "Women Legislature"
label variable head_of_gov_female "Woman Leader"
label variable total_cases_log "Total Cases"
label variable global_lag "Global Adoption"
label variable polity "Polity Score"
label variable gdp_per_capita_log "GDP Per Capita"
label variable pop_density_log "Population Density"
label variable system "Parliamentary System" // or parliament-elected president
label variable left "Left Government"

stset stop, id(country) f(status)
stcox head_of_gov_female percent_woman total_cases_log global_lag ///
	polity gdp_per_capita_log pop_density_log system left, efron
eststo school2

// MODEL 3A: INFO CAMPAIGN (officials urge caution)
use "info2.dta", clear
gen total_cases_log = log(total_cases)
gen gdp_per_capita_log = log(gdp_per_capita)
egen id = group(country)
gen pop_density_log = log(population_density)

label variable percent_woman "Women Legislature"
label variable head_of_gov_female "Woman Leader"
label variable total_cases_log "Total Cases"
label variable global_lag "Global Adoption"
label variable polity "Polity Score"
label variable gdp_per_capita_log "GDP Per Capita"
label variable pop_density_log "Population Density"
label variable system "Parliamentary System" // or parliament-elected president
label variable left "Left Government"

stset stop, id(id) f(status)
stcox head_of_gov_female percent_woman total_cases_log global_lag ///
	polity gdp_per_capita_log pop_density_log system left, efron
eststo info2

esttab stayhome2 school2 info2

esttab stayhome2 school2 info2 using "altoutcome.tex", alignment(D{.}{.}{-1}) ///
	eform mtitles("Stay Home" "School" "Info") label booktabs replace scalar("N_sub Countries") ///
	title(Alternative Outcome Measures\label{tab:alt-outcome}) star(+ 0.10 * 0.05 ** 0.01 *** 0.001)

*************************************************************
** ALTERNATIVE WINDOW
*************************************************************

use "stayhome3.dta", clear
gen total_cases_log = log(total_cases)
gen gdp_per_capita_log = log(gdp_per_capita)
egen id = group(country)
gen pop_density_log = log(population_density)

label variable percent_woman "Women Legislature"
label variable head_of_gov_female "Woman Leader"
label variable total_cases_log "Total Cases"
label variable polity "Polity Score"
label variable gdp_per_capita_log "GDP Per Capita"
label variable pop_density_log "Population Density"
label variable system "Parliamentary System" // or parliament-elected president
label variable left "Left Government"

stset stop, id(country) f(status)
stcox head_of_gov_female percent_woman total_cases_log ///
	polity gdp_per_capita_log pop_density_log system left, efron
eststo stayhome_date

use "school3.dta", clear
gen total_cases_log = log(total_cases)
gen gdp_per_capita_log = log(gdp_per_capita)
egen id = group(country)
gen pop_density_log = log(population_density)

label variable percent_woman "Women Legislature"
label variable head_of_gov_female "Woman Leader"
label variable total_cases_log "Total Cases"
label variable polity "Polity Score"
label variable gdp_per_capita_log "GDP Per Capita"
label variable pop_density_log "Population Density"
label variable system "Parliamentary System" // or parliament-elected president
label variable left "Left Government"

stset stop, id(country) f(status)
stcox head_of_gov_female percent_woman total_cases_log ///
	polity gdp_per_capita_log pop_density_log system left, efron
eststo school_date

use "info3.dta", clear
gen total_cases_log = log(total_cases)
gen gdp_per_capita_log = log(gdp_per_capita)
egen id = group(country)
gen pop_density_log = log(population_density)

label variable percent_woman "Women Legislature"
label variable head_of_gov_female "Woman Leader"
label variable total_cases_log "Total Cases"
label variable polity "Polity Score"
label variable gdp_per_capita_log "GDP Per Capita"
label variable pop_density_log "Population Density"
label variable system "Parliamentary System" // or parliament-elected president
label variable left "Left Government"

stset stop, id(country) f(status)
stcox head_of_gov_female percent_woman total_cases_log ///
	polity gdp_per_capita_log pop_density_log system left, efron
eststo info_date

esttab stayhome_date school_date info_date using "main-date.tex", alignment(D{.}{.}{-1}) ///
	eform mtitles("Stay Home" "School" "Info") label booktabs replace scalar("N_sub Countries") ///
	title(Alternative Window: January 1\label{tab:main-date}) star(+ 0.10 * 0.05 ** 0.01 *** 0.001)

***************************************************
** GROUP MEANS
***************************************************

use "stayhome.dta", clear
sort country start
by country: gen last = (_n == _N)
keep if last == 1
drop last
tab status
tab head_of_gov_female
bysort head_of_gov_female: tab status
bysort head_of_gov_female: sum stop if status == 1
keep if head_of_gov_female != .
rename stop stayhome
replace stayhome = 999 if status == 0
save "temp-stayhome.dta", replace

use "school.dta", clear
sort country start
by country: gen last = (_n == _N)
keep if last == 1
drop last
tab status
bysort head_of_gov_female: tab status
bysort head_of_gov_female: sum stop if status == 1
keep if head_of_gov_female != .
rename stop school
replace school = 999 if status == 0
save "temp-school.dta", replace

use "info.dta", clear
sort country start
by country: gen last = (_n == _N)
keep if last == 1
drop last
tab status
bysort head_of_gov_female: tab status
bysort head_of_gov_female: sum stop if status == 1
keep if head_of_gov_female != .
rename stop info
replace info = 999 if status == 0
save "temp-info.dta", replace

use "temp-stayhome.dta", clear
merge 1:1 country using "temp-school.dta", keepusing(school) nogen
merge 1:1 country using "temp-info.dta", keepusing(info) nogen
drop start status
order country stayhome school info
save "times.dta", replace
